home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / linux-ab.1 / linux-abuse.1.1.0.tar / abuse-1.10 / lisp / weapons.lsp < prev   
Lisp/Scheme  |  1995-10-23  |  13KB  |  475 lines

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licensing information for more details on usage rights
  3.  
  4.  
  5. (defun mbullet_ai ()
  6.   (if (> (state_time) 5)
  7.       nil
  8.     (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
  9.       (if (eq bx T)
  10.       T
  11.     (progn 
  12.       (if (null bx)
  13.           (if (eq (random 2) 0)
  14.           (progn
  15.             (add_panim MGUN_HIT1 (x) (y) (direction))
  16.             (play_sound MG_HIT_SND1 127 (x) (y)))
  17.         (progn
  18.           (add_panim MGUN_HIT2 (x) (y) (direction))
  19.           (play_sound MG_HIT_SND2 127 (x) (y))))
  20.         (progn
  21. ;          (add_panim EXPLO2 (x) (y) (direction))
  22. ;          (add_object EXP_LIGHT (x) (y) 80)    
  23.           (do_damage 5 bx (if (> 0 (direction)) -10 10) 0)
  24.           ))
  25.       nil))))
  26. )
  27.  
  28. (defun grenade_ai ()
  29.   (if (and (eq (tick) 0)
  30.        (if (< (total_objects) 1)
  31.            nil         
  32.          (let ((mex (x))
  33.            (mey (y)))
  34.            (not (with_object (get_object 0) (find_object_in_area (- mex 7) 
  35.                                      (- mey 7) 
  36.                                      (+ mex 7) 
  37.                                      (+ mey 7) bad_guy_list))))))
  38.       (progn (next_picture) T)
  39.     (do_explo 40 36)))
  40.  
  41. (defun fb_draw () nil)   ;; only draw while in the air
  42.  
  43. (defun firebomb_ai ()
  44.  
  45.   (add_object EXPLODE1 (- (x) (random 5)) (+ (y) (random 20)) 0)
  46.   (hurt_radius (x) (y) 60 40 (if (> (total_objects) 0) (get_object 0) nil) 10)     
  47.  
  48.   (and (or (< (state_time) 3) (not (eq (xvel) 0)))
  49.        (< (state_time) 20)
  50.        (select (direction)
  51.           (1 (progn ;(set_xvel 30) 
  52.             (not (blocked_right (move 0 0 0)))
  53.             ))
  54.           (-1 (progn ;(set_xvel -30) 
  55.              (not (blocked_left (move 0 0 0))))))))
  56.       
  57.  
  58.  
  59.  
  60.  
  61. (defun mbullet_ufun (creator) 
  62.   (set_direction (with_object creator (direction)))
  63.  
  64.   (let ((start (if (> (direction) 0) 335 155))
  65.     (end   (if (> (direction) 0) 25 205)))
  66.     (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
  67.       (if (and target (< (abs (- (x) (with_object target (x)))) 150)
  68.            (< (abs (- (y) (with_object target (y)))) 100))
  69.       (set_course (site_angle target) 50)
  70.     (if (> (direction) 0)
  71.         (set_course 0 50)
  72.       (set_course 180 50)))))
  73.  
  74.   (link_object creator)
  75. )
  76.  
  77.  
  78. (defun firebomb_ufun (creator) 
  79.   (set_direction (with_object creator (direction)))
  80.   (link_object creator)
  81. )
  82.  
  83.  
  84.  
  85. (defun player_mine_ufun (creator) 
  86.   (set_x (with_object creator (x)))
  87.   (set_y (with_object creator (y)))
  88.   (link_object creator)
  89.   (let ((me (me)))
  90.     (with_object creator (link_object me)))
  91. )
  92.  
  93. (defun player_mine_ai ()
  94.   (select (aistate)
  95.       (0
  96.        ;; wait till no player (just in case), or player lets go of fire button  
  97.        (if (or (eq 0 (total_objects)) 
  98.            (and (eq (with_object (get_object 0) (player_b1_suggest)) 0)
  99.             (eq (with_object (get_object 0) (player_b2_suggest)) 0)))
  100.            (progn
  101.          (set_state blocking)
  102.          (set_aistate 1)
  103.          T)
  104.          T))
  105.       (1 (if (next_picture)
  106.          T
  107.            (do_explo 50 40)
  108.          ))))
  109.       
  110.  
  111. (def_char MBULLET
  112.   (funs (ai_fun     mbullet_ai)  
  113.     (draw_fun   dev_draw)     ; you can't see the bullets
  114.     (user_fun   mbullet_ufun))
  115.   (range 10000 10000)
  116.   (flags (unlistable T))
  117.   (states "art/misc.spe" (stopped "mbullet_icon")))
  118.  
  119.  
  120. (defun grenade_ufun (creator) 
  121.   (set_direction (with_object creator (direction)))
  122.   (play_sound GRENADE_THROW 127 (x) (y))
  123.   (select (aitype)
  124.       (1 (progn (set_xvel (if (> (direction) 0) 
  125.                   (+ 13 (random 2)) 
  126.                 (+ -13 (random 2)))) (set_yvel -4)))
  127.       (2 (progn (set_xvel (if (> (direction) 0) 
  128.                   (+ 7 (random 2)) 
  129.                 (+ -7 (random 2)))) (set_yvel -10))))
  130.   (set_xvel (+ (xvel) (with_object creator (xvel))))
  131.   (link_object creator)
  132. )
  133.  
  134. (defun grenade_cache (type)
  135.   (list (list EXPLODE1 EXP_LIGHT) 
  136.     (list GRENADE_SND)))
  137.  
  138.  
  139. (def_char GRENADE
  140.   (funs (ai_fun   grenade_ai)  
  141.     (get_cache_list_fun grenade_cache)
  142.     (user_fun grenade_ufun))
  143.   (range 10000 10000)
  144.   (flags (unlistable  T))
  145.   (states "art/misc.spe" (stopped (seq "4gre" 1 8))))
  146.  
  147.  
  148. (def_char FIREBOMB
  149.   (funs (ai_fun   firebomb_ai)  
  150.     (user_fun firebomb_ufun)
  151.     (get_cache_list_fun grenade_cache)
  152.     (draw_fun fb_draw))
  153.   (abilities (walk_top_speed  20)
  154.          (run_top_speed   20))
  155.   (range 10000 10000)
  156.   (flags (unlistable T))
  157.   (states "art/misc.spe"
  158.       (stopped "firebomb")
  159.       (walking "firebomb")))
  160.  
  161. (defun giver (type)
  162.   (let ((amount (get_ability start_hp)))
  163.     (with_object (bg)
  164.          (progn 
  165.            (if (and (not (has_weapon type)) change_on_pickup)
  166.                (progn
  167.              (give_weapon type)
  168.              (set_current_weapon type))                          
  169.              (give_weapon type))
  170.            (add_ammo type amount)))))
  171.  
  172. (defun weapon_icon_ai () 
  173.   (if (activated)
  174.       (progn
  175.     (try_move 0 10)
  176.     (if (touching_bg) 
  177.         (progn
  178.           (play_sound AMMO_SND 127 (x) (y))
  179.           (select (otype)
  180.               (MBULLET_ICON5   (giver 0))    ;; these numbers correspond to status bar position
  181.               (MBULLET_ICON20  (giver 0))
  182.               (GRENADE_ICON2   (giver 1))        
  183.               (GRENADE_ICON10  (giver 1))
  184.  
  185.               (ROCKET_ICON2    (giver 2))
  186.               (ROCKET_ICON5    (giver 2))
  187.  
  188.               (FBOMB_ICON1     (giver 3))
  189.               (FBOMB_ICON5     (giver 3))
  190.  
  191.               (PLASMA_ICON20   (giver 4))
  192.               (PLASMA_ICON50   (giver 4))
  193.  
  194.               (LSABER_ICON50   (giver 5))
  195.               (LSABER_ICON100  (giver 5))
  196.  
  197.               (DFRIS_ICON4     (giver 6))
  198.               (DFRIS_ICON10    (giver 6))
  199.  
  200.               )
  201.  
  202.           nil)
  203.       T))
  204.     T))
  205.     
  206. (defun on_draw ()
  207.   (if (activated)
  208.       (draw)
  209.     (dev_draw)))
  210.       
  211.  
  212. (defun ammo_cache (type)    ;; tells what other chars to load in with this character
  213.   (list
  214.    (select type
  215.        (GRENADE_ICON2    `(,GRENADE ,GRENADE_TOP))
  216.        (GRENADE_ICON10   `(,GRENADE ,GRENADE_TOP))
  217.        (MBULLET_ICON5    `(,SHOTGUN_BULLET ,MGUN_TOP))
  218.        (MBULLET_ICON20   `(,SHOTGUN_BULLET ,MGUN_TOP))
  219.        (ROCKET_ICON2     `(,ROCKET ,ROCKET_TOP))
  220.        (ROCKET_ICON5     `(,ROCKET ,ROCKET_TOP))      
  221.        (FBOMB_ICON1      `(,FIREBOMB ,FIREBOMB_TOP))
  222.        (FBOMB_ICON5      `(,FIREBOMB ,FIREBOMB_TOP))
  223.  
  224.        (PLASMA_ICON20    `(,PLASMAGUN_BULLET))
  225.        (PLASMA_ICON50    `(,PLASMAGUN_BULLET))       
  226.  
  227.        (LSABER_ICON50    `(,LSABER_BULLET ,PGUN_TOP))
  228.        (LSABER_ICON100   `(,LSABER_BULLET ,PGUN_TOP))
  229.  
  230.        (DFRIS_ICON4      `(,DFRIS_BULLET ,DFRIS_TOP))
  231.        (DFRIS_ICON10     `(,DFRIS_BULLET ,DFRIS_TOP))
  232.    nil)))
  233.  
  234. (defun make_ammo_icon (symbol icon_name increment)
  235.   (eval (list 'def_char symbol          
  236.           '(funs (ai_fun weapon_icon_ai)
  237.              (get_cache_list_fun ammo_cache)
  238.              (draw_fun on_draw))
  239.           '(range 5 5)
  240.           '(flags (add_front T))
  241.           `(abilities (start_hp ,increment))
  242.           `(states  "art/chars/ammo.spe" (stopped ,icon_name)))))
  243.  
  244. (make_ammo_icon 'GRENADE_ICON2  "grenade_small" 2 )
  245. (make_ammo_icon 'GRENADE_ICON10 "grenade_large" 10)
  246.  
  247. (make_ammo_icon 'MBULLET_ICON5  "bullets_small"  5)
  248. (make_ammo_icon 'MBULLET_ICON20 "bullets_large" 20)
  249.  
  250. (make_ammo_icon 'FBOMB_ICON1 "firebomb_small"   1)
  251. (make_ammo_icon 'FBOMB_ICON5 "firebomb_large"   5)
  252.  
  253. (make_ammo_icon 'ROCKET_ICON2 "rocket_small"      2)
  254. (make_ammo_icon 'ROCKET_ICON5 "rocket_large"      5)
  255.  
  256.  
  257.  
  258. (defun guner_cons () 
  259.   (set_xvel 7)     ;; fire speed
  260.   (set_yvel 50)    ;; speed of bullet
  261.   (set_xacel 290)  ;; start angle
  262.   (set_yacel 359)  ;; end angle
  263. )
  264.  
  265.  
  266. (defun guner_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
  267.   (if (not (eq (state) stopped))
  268.       (progn
  269.     (add_object EXPLODE3 (+ hitx (random 5)) (+ hity (random 5)) 0)
  270.     (add_object EXPLODE2 (+ hitx (random 5)) (+ hity (random 5)) 2)
  271.     (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 1)
  272.     (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 2)
  273.  
  274.     (damage_fun amount from hitx hity 0 0)     ; don't allow pushing
  275.  
  276.     (if (<= (hp) 0)
  277.         (progn
  278.           (play_sound BLOWN_UP 127 (x) (y))
  279.           (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 25)) 0)      
  280.           (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 25)) 1)      
  281.           (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 10)) 2)      
  282.           (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 10)) 3) ))))
  283. )
  284.  
  285.  
  286.  
  287.  
  288.  
  289.         
  290. (defun shot_ai () (eq (bmove nil) T))
  291. (defun gun_ai ()
  292.   (if (> (hp) 0)
  293.       (progn
  294.     (select (state)
  295.         (stopped (if (> (state_time) (xvel))
  296.                  (let ((a (site_angle (bg)))
  297.                    (me (me))
  298.                    (speed (yvel)))
  299.                    (if (eq (aitype) 1)
  300.                    (print a))        ;; show the angle for level designers
  301.                    (if (and (>= a (xacel)) (<= a (yacel)) (if (> (direction) 0)
  302.                        (set_frame_angle 290 0 a)
  303.                      (set_frame_angle 180 250 a)))
  304.                    (progn
  305.                      (with_object (add_object VIS_SHOT
  306.                                   (+ (x) (* (cos a) 10)) 
  307.                                   (- (y) (+ 10 (* (sin a) 10))))
  308.                           (progn
  309.                             (play_sound MGUN_SND 127 (x) (y))
  310.                             (set_course a speed)
  311.                             (link_object me)))
  312.                           (set_aistate (+ (aistate) 1))
  313.                           (jump_state walking))))
  314.                nil))
  315.         (walking (jump_state blocking))
  316.         (blocking (jump_state stopped)))
  317.     T)
  318.     nil)
  319.   )
  320.  
  321.  
  322. (defun rocket_ai ()  
  323.   (if (not (frame_panic))
  324.       (let ((rand (rand_on)))
  325.     (with_object (add_object SMALL_LIGHT_CLOUD (+ (x) (random 3)) 
  326.                  (- (y) (random 3) (/ (picture_height) 2)))
  327.              (set_fade_count 11))
  328.     (set_rand_on rand)))
  329.  
  330.   (if (> (total_objects) 1)  ;; if not attached to object, just fly strait (0 is player)
  331.     (let ((angle (atan2 (- (- (y) (with_object (get_object 1) (y))) -15)
  332.             (- (with_object (get_object 1) (x)) (x) ))))
  333.       (let ((clock_dist (if (< angle (aistate))          ;; calculate clockwise andle distance
  334.                 (- (aistate) angle)
  335.               (+ (aistate) (- 360 angle)))))
  336.     (let ((closest_dist (if (> clock_dist 180) 
  337.                 (- 360 clock_dist)
  338.                   clock_dist)))
  339.       (let ((angle_add (if (> closest_dist 23)
  340.                    23
  341.                  (if (< closest_dist 5)
  342.                  0
  343.                    closest_dist))))
  344.         (if (> clock_dist 180)     ;; should we steer clock wise or counter?
  345.         (set_aistate (mod (+ (aistate) angle_add) 360))
  346.           (set_aistate (mod (+ (- (aistate) angle_add) 360) 360))) )))))
  347.  
  348.   (if (< speed max_speed)
  349.       (setq speed (+ speed 2)))
  350.   (set_course (aistate) speed)
  351.   (set_frame_angle 0 359 (aistate))
  352.   (if (or (eq (hp) 0)
  353.       (not (eq (bmove (if (> (total_objects) 0) (get_object 0) nil)) T)) 
  354.       (and (> (total_objects) 1) 
  355.            (< (abs (- (with_object (get_object 1) (x)) (x) )) 10)
  356.            (< (abs (- (- (with_object (get_object 1) (y)) (y)) 15 )) 10)))
  357.       (progn
  358.     (do_explo 40 50)
  359.     nil)
  360.   T))
  361.       
  362.  
  363. (defun rocket_ufun (creator) 
  364.   (link_object creator)
  365.   (play_sound ROCKET_SND 127 (x) (y))
  366.  
  367.   (let ((target (with_object creator (find_object_in_area 
  368.                       (- (x) 160) (- (y) 160)
  369.                       (+ (x) 160) (+ (y) 160) bad_guy_list))))
  370.     (select (aitype)
  371.         (1 (set_aistate (if (> (with_object creator (direction)) 0) 0 180)))
  372.         (2  (set_aistate (if (> (with_object creator (direction)) 0) 45 135))))
  373.     (if target (link_object target)))
  374.  
  375. )
  376.  
  377. (defun rocket_cache (type)
  378.   (list (list SMALL_LIGHT_CLOUD) nil))
  379.  
  380. (def_char ROCKET
  381.   (funs (ai_fun   rocket_ai)
  382.     (get_cache_list_fun rocket_cache)    
  383.     (get_cache_list_fun grenade_cache)
  384.     (user_fun rocket_ufun))
  385.   (vars speed max_speed)
  386.   (range 10000 10000)
  387.   (flags (unlistable T)
  388.      (hurtable T)
  389.      (add_front T))
  390.   (abilities (start_hp 4))
  391.   (states "art/missle.spe" (stopped  (seq "miss" 1 32))))
  392.  
  393.  
  394. /*
  395. (defun sgun_ai ()
  396.   (setq sgb_lastx (x))
  397.   (setq sgb_lasty (y))
  398.   (setq sgb_speed (/ (* sgb_speed 6) 5))
  399.   (set_course sgb_angle sgb_speed)  
  400.   (if (eq sgb_lifetime 0)
  401.       nil
  402.     (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
  403.       (setq sgb_lifetime (- sgb_lifetime 1))
  404.       (if (eq bx T) T
  405.     (progn
  406.       (setq sgb_lifetime 0)    ;; disappear next tick
  407.       (if (eq bx nil)
  408.           (add_object EXPLODE5 (- (x) (random 5)) (- (y) (random 5)) 0)
  409.         (progn
  410.           (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 0)
  411.           (do_damage 5 bx (* (cos sgb_angle) 10) (* (sin sgb_angle) 10))))))
  412.       T)))
  413.     */
  414.  
  415.  
  416. (defun sgun_draw ()
  417.   (draw_line sgb_lastx (- sgb_lasty 1) (x) (- (y) 1) sgb_medium_color)
  418.   (draw_line sgb_lastx (+ sgb_lasty 1) (x) (+ (y) 1) sgb_medium_color)
  419.  
  420.   (draw_line (- sgb_lastx 1) sgb_lasty (- (x) 1) (y) sgb_bright_color)
  421.   (draw_line (+ sgb_lastx 1) sgb_lasty (+ (x) 1) (y) sgb_medium_color)
  422.  
  423.  
  424.   (draw_line sgb_lastx sgb_lasty (x) (y) sgb_bright_color)
  425. )
  426.  
  427.  
  428. (defun sgun_ufun (creator) 
  429.   (set_direction (with_object creator (direction)))
  430.   (set_y (- (y) 4))
  431.   (set_x (+ (x) (* (direction) 20)))
  432.   (play_sound ZAP_SND 127 (x) (y))
  433.   (let ((start (if (> (direction) 0) 335 155))
  434.     (end   (if (> (direction) 0) 25 205)))
  435.     (setq sgb_speed 8)
  436.     (setq sgb_lastx (x))
  437.     (setq sgb_lasty (y))
  438.     (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
  439.       (if (and target (< (abs (- (x) (with_object target (x)))) 150)
  440.            (< (abs (- (y) (with_object target (y)))) 100))
  441.       (setq sgb_angle (site_angle target))
  442.     (if (> (direction) 0)        
  443.         (setq sgb_angle 0)
  444.       (setq sgb_angle 180)))))
  445.   (link_object creator)
  446. )
  447.  
  448.  
  449. (def_char SHOTGUN_BULLET
  450.   (vars sgb_speed sgb_angle sgb_lastx sgb_lasty 
  451.     sgb_bright_color sgb_medium_color sgb_lifetime)
  452.   (funs (ai_fun   sgun_ai)
  453.     (user_fun sgun_ufun)
  454.     (draw_fun sgun_draw))
  455.   (range 10000 10000)
  456.   (flags (unlistable T)
  457.      (add_front T))
  458.   (states "art/misc.spe" (stopped  "sgun_bullet")))
  459.  
  460.  
  461. (setq load_warn nil)
  462. (if (not (load "register/weapons.lsp"))
  463.     (load "lisp/share.lsp"))
  464. (setq load_warn T)
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.